package cn.ls;

import cn.ls.realm.CustomerMD5Realm004;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
import org.apache.shiro.mgt.DefaultSecurityManager;
import org.apache.shiro.subject.Subject;

public class TestCustomerMd5RealmAuthenticator004 {
    public static void main(String[] args) {
        //1.
        DefaultSecurityManager securityManager = new DefaultSecurityManager();
        //2.创建realm
        CustomerMD5Realm004 realm = new CustomerMD5Realm004();
        //密码加密
        HashedCredentialsMatcher credentialsMatcher = new HashedCredentialsMatcher();
        //md5加密
        credentialsMatcher.setHashAlgorithmName("md5");
        //散列次数
        credentialsMatcher.setHashIterations(1024);

        realm.setCredentialsMatcher(credentialsMatcher);

        securityManager.setRealm(realm);

        SecurityUtils.setSecurityManager(securityManager);

        Subject subject = SecurityUtils.getSubject();

        UsernamePasswordToken token = new UsernamePasswordToken("zhangsan", "123");

        subject.login(token);
    }
}
